<script setup lang="ts">
import { ref } from 'vue'
import { Menu as iconMenu } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
import { useUserInfoStore } from '@/store/userInfo.js'
import departmentMsg from '@/components/department_message.vue'
import { useMsg } from '@/store/message.js'

const msgStore = useMsg()
const userStore = useUserInfoStore()
msgStore.returnReadList(userStore.id)
const router = useRouter()
const exit = () => {
  router.replace('/login')
}
// 部门消息弹框
const department_msg = ref()
const openDepartmentMessage = () => {
  department_msg.value.open()
}
</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="200px">
        <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo" text-color="#fff"
          router>
          <div class="title">奖助学金评定管理系统</div>
          <el-menu-item index="home">
            <el-icon>
              <HomeFilled />
            </el-icon>
            <span>首页</span>
          </el-menu-item>
          <el-menu-item index="overview">
            <el-icon>
              <icon-menu />
            </el-icon>
            <span>系统概览</span>
          </el-menu-item>
          <el-sub-menu index="3" v-if="userStore.identity == '超级管理员'">
            <template #title>
              <el-icon>
                <UserFilled />
              </el-icon>
              <span>用户管理</span>
            </template>
            <el-menu-item-group title="管理员管理">
              <el-menu-item index="superManager">超级管理员</el-menu-item>
              <el-menu-item index="manager">普通管理员</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="学生管理">
              <el-menu-item index="student">学生列表</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-sub-menu index="4">
            <template #title>
              <el-icon>
                <Notification />
              </el-icon>
              <span>流程管理</span>
            </template>
            <el-menu-item-group title="发起申请">
              <el-menu-item index="applyScholarship">奖学金申请</el-menu-item>
              <el-menu-item index="applyAid">助学金申请</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="审核" v-if="userStore.identity !== '用户'">
              <el-menu-item index="auditByGroup"
                v-if="userStore.identity == '超级管理员' || userStore.identity == '管理员' || userStore.identity == '审核小组'">审核小组审核</el-menu-item>
              <el-menu-item index="auditByTutor"
                v-if="userStore.identity == '超级管理员' || userStore.identity == '辅导员' || userStore.identity == '院领导'">辅导员/院领导审核</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-sub-menu index="5" v-if="userStore.identity == '超级管理员'">
            <template #title>
              <el-icon>
                <Message />
              </el-icon>
              <span>消息管理</span>
            </template>
            <el-menu-item-group title="消息管理">
              <el-menu-item index="message_list">消息列表</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="回收站">
              <el-menu-item index="recycle">回收站</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-menu-item index="application">
            <el-icon>
              <Document />
            </el-icon>
            <span>奖助学金项目管理</span>
          </el-menu-item>
          <el-menu-item index="operationLog" v-if="userStore.identity == '超级管理员'">
            <el-icon>
              <List />
            </el-icon>
            <span>操作日志</span>
          </el-menu-item>
          <el-menu-item index="loginLog" v-if="userStore.identity == '超级管理员'">
            <el-icon>
              <TrendCharts />
            </el-icon>
            <span>登录日志</span>
          </el-menu-item>
          <el-sub-menu index="6">
            <template #title>
              <el-icon>
                <ChatDotRound />
              </el-icon>
              <span>举报与反馈</span>
            </template>
            <el-menu-item-group title="反馈管理">
              <el-menu-item index="feedback_form">提交反馈</el-menu-item>
              <el-menu-item index="feedback_list">我的反馈</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="超级管理员" v-if="userStore.identity == '超级管理员'">
              <el-menu-item index="feedback_admin">反馈管理</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-menu-item index="setting">
            <el-icon>
              <Tools />
            </el-icon>
            <span>系统设置</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <span class="header-left-content">尊敬的&nbsp;{{ userStore.name }}&nbsp;,欢迎使用奖助学金评定管理系统!</span>
          <div class="header-right-content">
            <el-badge :is-dot='msgStore.read_list.length > 0 ? true : false' class="item"
              @click="openDepartmentMessage">
              <el-icon :size="20" class="message" style="cursor: pointer;">
                <Message />
              </el-icon>
            </el-badge>
            <el-avatar :size="24" :src="userStore.imageUrl" />
            <el-dropdown>
              <span class="el-dropdown-link">
                设置
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>设置账号</el-dropdown-item>
                  <el-dropdown-item>更改头像</el-dropdown-item>
                  <el-dropdown-item @click="exit">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
  <departmentMsg ref="department_msg"></departmentMsg>
</template>


<style scoped lang="scss">
.el-aside {
  height: 100vh;
  background: #2b303b;
  width: 210px;
  //隐藏因为子菜单带来的溢出滚动条
  overflow-x: hidden;

  .el-menu {
    background: #2b303b;
    width: 210px;
    height: 100vh;
    border-right: 0px;
  }

  .title {
    padding: 20px;
    display: flex;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    background: #2b303b;
  }
}

.el-header {
  display: flex;
  height: 55px;
  background: #262f3e;
  color: #c1c6c8;
  align-items: center;
  justify-content: space-between;

  .header-left-content {
    font-size: 14px;
  }

  .header-right-content {
    display: flex;
    width: 160px;
    justify-content: space-around;
    align-items: center;
  }
}

.el-main {
  --el-main-padding: 0;
  background-color: #f3f4fa;
}

.el-menu-item:hover {
  background: #006eff;
}

:deep(.el-sub-menu__title):hover {
  background: #006eff;
}

:deep(.el-menu--inline) {
  background: #2b303b;
}
</style>